<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en">
<head>
<title>电台数据设置</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="icon" href="favicon.ico" type="image/x-icon" />
<!-- END META SECTION -->

<!-- CSS INCLUDE -->        
      
<link rel="stylesheet" href="${ctx}/rs/js/zTree/css/zTreeStyle/metro.css"/>
<link rel="stylesheet" href="${ctx}/rs/css/bootstrap-table.css" />
<link rel="stylesheet" href="${ctx}/rs/css/main.css" />
<link id="theme" rel="stylesheet" href="${ctx}/rs/joli/css/theme-default.css" />

<!-- EOF CSS INCLUDE -->
<style type="text/css">

    .setRouse .col-sm-8 input{display: inline-block;}
    .counts_Div{text-align: left}
    .setRouse .form-control{width: 200px;}
    .tipError{color:red;}
    .counts_Span{display: inline-block;width: 110px;text-align:right;margin-right:15px;}
    .dataTips{float:right;font-weight: bold;}
    .borColor{border-color:#d9534f;}

</style>        
</head>
<body >

     <!-- START PAGE CONTAINER -->
      <div class="page-container">
        <!-- 引入左菜单部分 -->
          <jsp:include page="../joli/menu.jsp"></jsp:include>
          
          <!-- START PAGE CONTENT -->
          <div class="page-content">
              <jsp:include page="../joli/top.jsp"></jsp:include>
              
              <!-- START BREADCRUMB -->
              <ul class="breadcrumb">
                  <li><a href="#">媒体推荐</a></li>                    
                  <li class="active">电台数据设置</li>
              </ul>
              <!-- END BREADCRUMB -->   
              
              
              <!-- PAGE CONTENT WRAPPER -->
              <div class="page-content-wrap">
                <div class="row">
                    <div class="col-xs-12">
                        <div id="toolbar" style ="text-align: center;" >
	                          <div id = "success">
	                        
	                          
                            </div>
                           <div class="row">
                             <div class="notInfo  display_none" id="role_id" >
	                            <label for="recipient-name" class="control-label col-sm-4">入驻客户名称</label>
	                             <input type="text"  class="col-sm-4" style="height: 30px;" id="user_name" name ="user_name"/>
	                            <label for="recipient-name" class="control-label col-sm-4">
	                            <input type="radio"  name="radiobutton"   checked="checked"  value="4">媒体主
	                            <input type="radio"  name="radiobutton"   value="5" >广告主
	                            </label>
                             </div>
	                              <button class="btn btn-primary btn-sm srt-btn active" onclick="LocatedSave()">确认公布</button>
                            </div>
                        </div>
                        <table id="table" cellpadding="0" cellspacing="0" data-toggle="table" data-toolbar="#toolbar"
                            data-url="${ctx}/located/BsqxLocatedUserList.htm"
                            data-cache="false"
                            data-pagination="true" 
                            data-side-pagination="server"
                            data-page-list="[10, 20, 50, 100]"
                            data-response-handler=responseHandler
                            data-page-size="20"  
                            data-query-params="queryParams">
                            <thead>
                                <tr class="tab-th">
                                    <th data-field="id">编号</th>
                                    <th data-field="role_id" class="col-md-2" data-formatter="positionFormatter">客户类型</th>
                                    <th data-field="user_name" class="col-md-4">客户名称</th>
                                    <th data-field="create_time" data-formatter="timeFormatter">发布日期</th>
                                    <th data-field="status" data-formatter="statusFormatter">状态</th>
                                    <th data-field="action" class="col-md-2" data-formatter="actionFormatter">操作</th>
                                </tr>
                            </thead>
                        </table>
                        
                    </div>
                </div>
              </div>  
         </div>
     </div>
          <!-- 引入所有joli的脚本 -->
    <jsp:include page="../joli/scripts.jsp"></jsp:include>
    <!-- 引入页面需要的脚本 -->
    <script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
    <script src="${ctx}/rs/js/zTree/js/jquery.ztree.all-3.5.min.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table-zh-CN.js"></script>
    <script src="${ctx}/rs/js/jquery.formatDate.js"></script>
    <script src="${ctx}/rs/js/my97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/rs/js/session-out-error.js"></script>
    <script type="text/javascript">
    activeMenu($("#menu_media_2"));
    var $table = $('#table');
    $table.on('click-row.bs.table', function (e, row, $element) {
        $table.bootstrapTable('uncheckAll');
        $table.bootstrapTable('check', $element.index());
    });
    
    $table.bootstrapTable({
        height: getHeight()
    });


    
    //获取分辨率高度
    function getHeight() {
        return window.screen.height - 308;
    }
    
    $(window).resize(function () {
        $table.bootstrapTable('resetView',{height: getHeight()});
    });
    //初始化刷新
   function refresh(pageIndex,selectPage){
        if(!pageIndex && !selectPage){
            pageIndex = 0;
            selectPage = 0;
        }
        var pageSize = $table.bootstrapTable('getOptions').pageSize;
        pageIndex=pageIndex*pageSize;
        $table.bootstrapTable('refresh', {
            silent: true,
            cache : false,
            url: '${ctx}/located/LocatedUserList.htm',
            query: {
                status:status,
                pageIndex : pageIndex,
                pageSize : pageSize
            }
        });
        $table.bootstrapTable('selectPage', selectPage);
    }

   function queryParams(params) {
       return {
           pageIndex : params.offset,
           pageSize : params.limit
       };
   }

   

   function mediaSave (){
    	var media_counts = $("#media_counts").val()*1,people_counts = $("#people_counts").val()*1,
      area_counts = $("#area_counts").val()*1,county_counts= $("#county_counts").val()*1;

    	var plant_id = $("#plant_id").val(); 
      $(".tipError").html("");
      var reg   =   /^[0-9]*[1-9][0-9]*$/
      var mediaFlag = true,peopleFlag = true,areaFlag = true;
      var $Media  = $("#media_counts"),$people =  $("#people_counts"),$area =$("#area_counts"),$county = $("#county_counts");

      var regMedia =  /^[0-9]+([.]{1}[0-9]{1,2})?$/;
      if(media_counts && regMedia.test(media_counts) && media_counts<100){
            $Media.val(media_counts.toFixed(2))
            $(".tipError").html(" ");
            $Media.removeClass("borColor");
            mediaFlag = true;
      }else{
          $Media.addClass("borColor");
          mediaFlag = false;
          $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
          return;
      }

      var regPeople= /^[0-9]+([.]{1}[0-9]{1,2})?$/;
      if(people_counts && regPeople.test(people_counts) && mediaFlag){
            $people.removeClass("borColor")
            $(".tipError").html(" ");
            peopleFlag= true;
      }else{
            $people.addClass("borColor");
            peopleFlag= false;
            $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
            return 
      }

      if(area_counts && reg.test(area_counts) && mediaFlag && peopleFlag){
          $(".tipError").html(" ");
          $area.removeClass("borColor");
          areaFlag = true;
      }else{
          $area.addClass("borColor");
          areaFlag = false;
          $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
          return;
      }

      if(county_counts && reg.test(county_counts) && mediaFlag && peopleFlag && areaFlag){
          $(".tipError").html(" ");
          $county.removeClass("borColor");
          $.ajax({
              url: "${ctx}/located/bsqxmediaSave.htm",
              type: "post",
              data: {
                media_counts:media_counts,
                people_counts:people_counts,
                area_counts:area_counts,
                county_counts:county_counts
              },
              success: function (text) {
                  
                  if(!$('.unable').is(':hidden')){
                      $(".unable").hide();
                  }
                  // 普通消息提示条
                  bootstrapQ.msg({
                      msg : '发送消息成功！',
                      type : 'success',
                      time : 2000
                  });
                  alert("发布成功");
                  //触发隐藏确认的按钮，引用回调方法关闭窗口并刷新列表
                  $("button.bsok").click();
                  setTimeout("window.location.reload(true)",2000);
              }
          });

      }else{
          $county.addClass("borColor")
          $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
          return;
      }
     
      
     
    	
    	
    	
    }
    function LocatedSave(){
    	var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
        var pageIndex = pageNumber - 1;
    	var user_name = $("#user_name").val();
    	if(user_name==""){
    		alert("请输入客户名称");
    		return ;
    	}
    	var role_id =$("#role_id input[name='radiobutton']:checked").val();
    	$.ajax({
            url: "${ctx}/located/save.htm",
            type: "post",
            data: {
            	user_name:user_name,
            	role_id:role_id
            },
            success: function (text) {
                // 普通消息提示条
                bootstrapQ.msg({
                    msg : '发送消息成功！',
                    type : 'success',
                    time : 2000
                });
                alert("发布成功");
                //触发隐藏确认的按钮，引用回调方法关闭窗口并刷新列表
                setTimeout("window.location.reload(true)",2000);
            }
        });
    }
    


    
    function timeFormatter(value, row, index){
    	 if(value){
             return $.formatDate("yyyy-MM-dd HH:mm:ss", new Date(value));
         }
         return "--";
    }
    function statusFormatter(value, row, index){
        var retbak="";
        switch(row.status){
        case 1:
            retbak="公布中"
            break;
        case 0:
            retbak="已撤销"
            break;
        }
        return retbak;
    }
    
    function actionFormatter(value, row, index){
        var retbak="";
        switch(row.status){
    
        case 0:
            retbak='<a class="mr15" href="javascript:open('+row.id+',1)">公布</a>';
            break;
        case 1:
            retbak='<a class="mr15" href="javascript:open('+row.id+',0)">撤销公布</a>';
            break;

        }
        return retbak;
    }


    function responseHandler(res){
        // TODO 数据加到页面
           var html="";
               html += '  <div  id ="success" >'+
                          ' <label for="recipient-name" id = "app">'+"截止当前平台已创建app  "+res.app+" 个"+'</label><br>'+
                          ' <label for="recipient-name" id = "wet">'+"截止当前平台已创建微信公众号  "+res.wet+" 个"+'</label><br>'  +
                          ' <label for="recipient-name" id = "fm">'+"截止当前平台已创建频率  " +res.fm+" 个"+'</label><br>'+
                          ' <label for="recipient-name"id = "adver">'+"截止当前平台已发布综合广告       "+res.adver+" 个"+'</label><br>'+
                          ' <input type="hidden" id = "plant_id" value='+res.plant_id+'> '+
                          ' </div>'+
                          '<div class="row setRouse form-group clearfix form-cus-group ">'+
                          ' <input type="hidden" id = "plant_id" value="${plant_id}">'+
                          '<label for="recipient-name" class="control-label col-sm-4">'+"平台媒体资源数据设置"+'</label>'+
                          '<div class="col-sm-8 col-cus-auto">'+
                          '<div class="counts_Div"><span class="counts_Span">全国区县台覆盖</span><input type="text" class="form-control" min="0" max="9.99" id="media_counts" name ="media_counts" value='+res.media_counts+'> %</div>'+
                          '<div class="counts_Div"><span class="counts_Span">覆盖人口</span><input type="text" class="form-control" min="0" id="people_counts" name ="people_counts" value='+res.people_counts+'> 亿  <span class="dataTips">'+"此数据将公布在云道平台登录首页"+'</span> </div>'+
                          '<div class="counts_Div"><span class="counts_Span">覆盖地区</span><input type="text" class="form-control"  min="0" id="area_counts" name ="area_counts" value='+res.area_counts+'></div>'+
                          '<div class="counts_Div"><span class="counts_Span">各县区市</span><input type="text" class="form-control" min="0" id="county_counts" name ="county_counts" value='+res.county_counts+'> </div></div></div>'+
                          '<div class="form-cus-group"><label for="recipient-name" class="control-label col-sm-4">  &nbsp;</label><div class="col-sm-8 col-cus-auto counts_Div"><span class="tipError"></span></div></div>'+
                          '<div class="text-center" style="clear:both">'+
                          '<button class="btn btn-primary btn-sm srt-btn active" onclick="mediaSave()">'+"确认公布"+'</button>'+
                          '</div>';
              $("#success").html(html);
              var mediaFlag = true,peopleFlag = true,areaFlag = true;
              $("#media_counts").blur(function(){
                    // var reg = /^\d+(\.\d{2})?$/;
                    var reg = /^[0-9]+([.]{1}[0-9]{1,2})?$/;
                    var thisVal = ($(this).val())*1;
                    if(thisVal && reg.test(thisVal) && thisVal<100){
                        $(".tipError").html(" ");
                        $(this).removeClass("borColor");
                        mediaFlag = true;
                    }else{
                        $(this).addClass("borColor");
                        mediaFlag = false;
                        $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
                    }
                })

                $("#people_counts").blur(function(){
                    var regPeople= /^[0-9]+([.]{1}[0-9]{1,2})?$/;
                    var thisVal = ($(this).val())*1;
                    if(thisVal && regPeople.test(thisVal) && mediaFlag){                      
                        $(this).removeClass("borColor")
                        $(".tipError").html(" ");
                        peopleFlag= true;
                    }else{
                        $(this).addClass("borColor");
                        peopleFlag= false;
                        $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
                    }
                })

                $("#area_counts").blur(function(){
                    var reg   = /^[0-9]*[1-9][0-9]*$/
                    var thisVal = ($(this).val())*1;
                    if(thisVal && reg.test(thisVal) && mediaFlag && peopleFlag){
                        $(".tipError").html(" ");
                        $(this).removeClass("borColor");
                        areaFlag = true;
                    }else{
                        $(this).addClass("borColor");
                        areaFlag = false;
                        $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
                    }
                })

                $("#county_counts").blur(function(){
                    var reg   =   /^[0-9]*[1-9][0-9]*$/
                    var thisVal = ($(this).val())*1;
                    if(thisVal && reg.test(thisVal) && areaFlag && mediaFlag && peopleFlag){
                        $(".tipError").html(" ");
                        $(this).removeClass("borColor")
                    }else{
                        $(this).addClass("borColor")
                        $(".tipError").html("格式不正确或数据不完整,请输入正确的数据");
                    }
                })

              

        return res;
    }
     

//  更改状态
    function open(id,status){
		$.ajax({
            url: "${ctx}/located/save.htm",
           type: 'POST',
           data: {
               id:id,
               status:status
           },
             success: function (text) {
                 bootstrapQ.msg({
                     msg  : '操作成功！',
                     type : 'success',
                     time : 2000
                 });
                 setTimeout("window.location.reload(true)",1000);
             },
             error: function () {
                 bootstrapQ.msg({
                     msg  : '操作失败！',
                     type : 'danger',
                     time : 2000
                 });
                 setTimeout("window.location.reload(true)",1000);
             }
         });
    }
    function positionFormatter(value, row, index){
    	var retbak="";
        switch(row.role_id){
    
        case 4:
            retbak="<sapn class='label label-info'>媒体主</span>";
            break;
        case 5:
            retbak="<span class='label label-info'>广告主</span>"
            break;

        }
        return retbak;
    }

 // $(function time (){
//  debugger;
//     var time = '';
//     var put_starttime =$("#put_starttime").val();
    var put_endtime =$("#put_endtime").val();
//     if(put_starttime==''&& put_starttime==null){
//      time="不限";
//     }else{
//      put_starttime =$.formatDate("yyyy-MM-dd HH:mm:ss", new Date(put_starttime)) ;
        put_endtime = $.formatDate("yyyy-MM-dd HH:mm:ss", new Date(put_endtime));
//      time = put_starttime;
//     }
//     $("#put_starttime").val(time)
// }
// )

    </script>
    
  </body >
</html>
